/**
 * 
 */
package qualification2010;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Hashtable;

/**
 * @author Coddy created on 2010-5-7
 * 
 */
public class T9Spelling
{
	static Hashtable<Character, Integer> table;
	static String largeInput = "C-large-practice.in";
	static String largeOutput = "C-large-practice.out";
	static String smallInput = "C-small-practice.in";
	static String smallOutput = "C-small-practice.out";

	static String currentInput = largeInput;
	static String currentOutput = largeOutput;

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		init();
		try
		{
			BufferedReader bf = new BufferedReader(new FileReader(currentInput));
			BufferedWriter bw = new BufferedWriter(
					new FileWriter(currentOutput));
			int n = Integer.parseInt(bf.readLine());

			for (int i = 1; i <= n; i++)
			{
				StringBuffer sb = new StringBuffer();
				sb.append("Case #" + i + ": ");
				char last = '+';
				String line = bf.readLine();
				char[] characters = line.toCharArray();
				for (int j = 0; j < characters.length; j++)
				{
					Character character = new Character(characters[j]);
					if (getCharButton(last) == getCharButton(characters[j]))
						sb.append(" ");
					sb.append(table.get(character));
					last = characters[j];
				}

				bw.write(sb.toString() + "\n");
				bw.flush();

			}
		} catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NumberFormatException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static void init()
	{
		table = new Hashtable<Character, Integer>();
		table.put('a', 2);
		table.put('b', 22);
		table.put('c', 222);
		table.put('d', 3);
		table.put('e', 33);
		table.put('f', 333);
		table.put('g', 4);
		table.put('h', 44);
		table.put('i', 444);
		table.put('j', 5);
		table.put('k', 55);
		table.put('l', 555);
		table.put('m', 6);
		table.put('n', 66);
		table.put('o', 666);
		table.put('p', 7);
		table.put('q', 77);
		table.put('r', 777);
		table.put('s', 7777);
		table.put('t', 8);
		table.put('u', 88);
		table.put('v', 888);
		table.put('w', 9);
		table.put('x', 99);
		table.put('y', 999);
		table.put('z', 9999);
		table.put(' ', 0);
	}

	private static int getCharButton(char c)
	{
		int buttonID;
		switch (c)
		{
		case 'a':
		case 'b':
		case 'c':
			buttonID = 2;
			break;
		case 'd':
		case 'e':
		case 'f':
			buttonID = 3;
			break;
		case 'g':
		case 'h':
		case 'i':
			buttonID = 4;
			break;
		case 'j':
		case 'k':
		case 'l':
			buttonID = 5;
			break;
		case 'm':
		case 'n':
		case 'o':
			buttonID = 6;
			break;
		case 'p':
		case 'q':
		case 'r':
		case 's':
			buttonID = 7;
			break;
		case 't':
		case 'u':
		case 'v':
			buttonID = 8;
			break;
		case 'w':
		case 'x':
		case 'y':
		case 'z':
			buttonID = 9;
			break;
		case ' ':

			buttonID = 0;
			break;
		default:
			buttonID = 100;
			break;
		}
		return buttonID;
	}
}
